package com.pingan.pastry.common.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

public class CookieUtils {

    public static void setCookie() {

    }

    public static String getCookieValueByName(HttpServletRequest request, String name) {
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            try {
                for (Cookie cookie : cookies) {
                    if (name.equals(cookie.getName())) {
                        return URLDecoder.decode(cookie.getValue(), "UTF-8");
                    }
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("df");
        list.add("rtr");
        try {
            for (String s : list) {
                System.out.println(s);
                testException();

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void testException() throws Exception {
        throw new Exception("ce");
    }

}
